package com.wuxiaofan.api;

import com.wuxiaofan.event.LogEvent;
import com.wuxiaofan.event.NoteEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("test")
public class TestApi {

    @Resource
    ApplicationContext applicationContext;
    @GetMapping("test1/{name}")
    public String test1(@PathVariable String name){
        log.info("name:{}",name);
        applicationContext.publishEvent(new LogEvent(this,"id",name,"msg"+name));
        log.info("执行完成");
        return "完成";
    }

    @GetMapping("test2")
    public String test2(String name){
        log.info("name:{}",name);
        applicationContext.publishEvent(new LogEvent(this,"id",name,"msg"+name));
        log.info("执行完成");
        return "完成";
    }

    @GetMapping("test3")
    public String test3(String context){
        log.info("controller  context:{}",context);
        applicationContext.publishEvent(new NoteEvent(this,context));
        log.info("执行完成 test3");
        return "完成";
    }
}
